<template>
  <van-search shape="round" placeholder="请输入搜索关键词" show-action class="search" v-model="text">
    <template #left>
      <van-icon name="arrow-left" color="#fff" @click="reto" />
    </template>

    <template #action>
      <span @click="search">搜索</span>
    </template>
  </van-search>

  <div class="video" v-for="item in state.videos">
    <img :src="item.img" alt="" :key="item.id">
    <div class="text">
      <div class="introduce">{{ item.title }}</div>
      <div class="author">{{ item.author }}</div>
      <div class="date">
        <span class="number">{{ item.number }}</span>
        <span>{{ item.date }}</span>
        <span class="icon">:</span>
      </div>
    </div>
  </div>
</template>
  
<script setup>
import { useRoute, useRouter } from 'vue-router';
import axios from '../api/index.js'
import { ref } from 'vue';
import { onBeforeMount } from 'vue';
import { reactive } from 'vue';

const text = ref('')
const route = useRoute()
const router = useRouter()
text.value = route.query.text
const state = reactive({
  videos: []
})
const reto = () => {
  router.push('/search')
}
onBeforeMount(
  async () => {
    const res = await axios.post('/search', { text: text.value })
    state.videos = res.data
    console.log(state.videos)
  }
)


</script>
  
<style lang="less" scoped>
.search {
  background: #ff279aec
}

.video {
  left: 5%;
  width: 95%;
  padding-top: 0.15rem;
  position: relative;
  display: flex;
  border-bottom: 1px solid #ccc;

  img {
    width: 4rem;
    height: 2.25rem;
    border-radius: 0.1rem;
  }

  .text {
    flex: 1;
    padding: 0.15rem;

    .introduce {
      font-size: 0.4rem;
      height: 1rem;
    }

    .author,
    .date {
      padding: 0.15rem 0;
      font-size: 0.36rem;
      color: #000;
    }

    .date {
      position: relative;
      display: flex;
      align-items: center;

      .icon {
        position: absolute;
        right: 0.1rem;
      }

      .number {
        margin-right: 0.4rem;
        position: relative;
      }

      .number::after {
        content: '.';
        font-size: 0.5rem;
        position: absolute;
        bottom: 0.1rem;
        right: -0.3rem;
      }
    }
  }

}
</style>